package com.kwlt.smc.entity;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kwlt.smc.util.ConUtils;
import com.kwlt.smc.util.Constants;
import com.kwlt.smc.web.SendSmsController;

/**
 * 短信接口信息
 * @author xushunxin
 *
 */
public class SmsInfo {
	
	public static Logger logger =  LoggerFactory.getLogger(SendSmsController.class);
	
	/**
	 * 下行目的手机号,支持批量发送，多个手机号之间用英文半角逗号(,)分隔
	 */
	private String dest;
	/**
	 * 下行短信内容，有非英文字符需要进行URLEncode指定字符集UTF-8
	 */
	private String msg;
	/**
	 * 用户名
	 */
	private String user;
	/**
	 * 密码
	 */
	private String pwd;
	/**
	 * 扩展号码
	 */
	private String ext = "";
	/**
	 * 通道编号
	 */
	private String cc;
	/**
	 * 消息类型0：默认是普通短信；1：二进制；2：wap push
	 */
	private String msgtype;
	/**
	 * 消息编号
	 */
	private String msgid;
	/**
	 * [dest+msg+md5密钥]用md5数字签名并转为16进制格式（长度为32字节）
	 * ，如果双方约定不使用MD5密钥可以不使用这个字段
	 */
	private String authcode;
	/**
	 * IP地址
	 */
	private String ip;
	/**
	 * 扩展1
	 */
	private String extParm1;
	/**
	 * 扩展2
	 */
	private String extParm2;
	/**
	 * 扩展3
	 */
	private String extParm3;
	/**
	 * 扩展4
	 */
	private String extParm4;
	/**
	 * 是否保存redis
	 */
	private String isRedis;
	/**
	 * 移动通道编号
	 */
	private Set mobileChannelSet = new HashSet();
	/**
	 * 联通通道编号
	 */
	private Set unicomChannelSet = new HashSet();
	/**
	 * 电信通道编号
	 */
	private Set telecomChannelSet = new HashSet();
	/**
	 * 最终的短信内容，判断是否长短信。
	 * 如果用户配置了签名，则内容为用户提交的内容加上配置的签名，否则如果通道
	 * 带签名。则加上通道的签名。
	 */
	private String result;
	private User ouser;
	
	/**
	 * 发送时间
	 */
	private String sendtime;
	
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public String getUser() {
		return user;
	}
	public void setUser(String user) {
		this.user = user;
	}
	public String getDest() {
		if(StringUtils.isBlank(dest))
			return dest;
		HashSet<String> set = new HashSet<String>();
		StringBuffer sb = new StringBuffer();
		for (String phone : dest.split(Constants.REXG)) {
			if(!set.contains(phone)){
				set.add(phone);
				if(ConUtils.isPhoneNo(phone)){
					//如果是手机号，则放入手机号
					sb.append(phone).append(",");
				}else{
					//记录一下
					logger.info("moberr:"+phone+"\t"+this.user+"\t"+this.msg);
				}
			}
		}
		if(sb.toString().length()>0){
			dest = sb.toString().substring(0,sb.toString().length()-1);
		}
		/*if(dest!=null && !"".equals(dest)){
			HashSet<String> set = new HashSet<String>();
			for (String phone : dest.split(Constants.REXG)) {
				set.add(phone);
			}
			StringBuffer sb = new StringBuffer();
			if(set!=null && set.size()>0){
				for(String phone:set){
					if(ConUtils.isPhoneNo(phone)){
						//如果是手机号，则放入手机号
						sb.append(phone).append(",");
					}else{
						//记录一下
						logger.info("moberr:"+phone+"\t"+this.user+"\t"+this.msg);
					}
				}
			}
			if(sb.toString().length()>0){
				dest = sb.toString().substring(0,sb.toString().length()-1);
			}
		}*/
		return dest;
	}
	public void setDest(String dest) {
		this.dest = dest;
	}
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	public String getExt() {
		return ext;
	}
	public void setExt(String ext) {
		this.ext = ext;
	}
	public String getCc() {
		return cc;
	}
	public void setCc(String cc) {
		this.cc = cc;
	}
	public String getMsgtype() {
		return msgtype;
	}
	public void setMsgtype(String msgtype) {
		this.msgtype = msgtype;
	}
	public String getMsgid() {
		return msgid;
	}
	public void setMsgid(String msgid) {
		this.msgid = msgid;
	}
	public String getAuthcode() {
		return authcode;
	}
	public void setAuthcode(String authcode) {
		this.authcode = authcode;
	}
	public String getIp() {
		return ip;
	}
	public void setIp(String ip) {
		this.ip = ip;
	}
	
	
	public Set getMobileChannelSet() {
		return mobileChannelSet;
	}
	public void setMobileChannelSet(Set mobileChannelSet) {
		this.mobileChannelSet = mobileChannelSet;
	}
	public Set getUnicomChannelSet() {
		return unicomChannelSet;
	}
	public void setUnicomChannelSet(Set unicomChannelSet) {
		this.unicomChannelSet = unicomChannelSet;
	}
	public Set getTelecomChannelSet() {
		return telecomChannelSet;
	}
	public void setTelecomChannelSet(Set telecomChannelSet) {
		this.telecomChannelSet = telecomChannelSet;
	}
	public User getOuser() {
		return ouser;
	}
	public void setOuser(User ouser) {
		this.ouser = ouser;
	}
	public String getExtParm1() {
		return extParm1;
	}
	public void setExtParm1(String extParm1) {
		this.extParm1 = extParm1;
	}
	public String getExtParm2() {
		return extParm2;
	}
	public void setExtParm2(String extParm2) {
		this.extParm2 = extParm2;
	}
	public String getExtParm3() {
		return extParm3;
	}
	public void setExtParm3(String extParm3) {
		this.extParm3 = extParm3;
	}
	public String getExtParm4() {
		return extParm4;
	}
	public void setExtParm4(String extParm4) {
		this.extParm4 = extParm4;
	}
	public String getIsRedis() {
		return isRedis;
	}
	public void setIsRedis(String isRedis) {
		this.isRedis = isRedis;
	}
	
	public String getSendtime() {
		return sendtime;
	}
	public void setSendtime(String sendtime) {
		this.sendtime = sendtime;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	
}
